<?php

namespace app\admin\controller;

use think\Controller;
use app\common\model\ReplyModel;
class WechatkeywordController extends Controller
{
    public function index()
    {
        if($this->request->isAjax())
        {
            $reply=new ReplyModel();
            $post=$this->request->post();
            $result=$reply->getKeywords($post["page"],$post["limit"]);   
            return \pagejson($result["data"],$result["count"]);
        }
        return view();
    }

    public function create()
    {
        if($this->request->isAjax())
        {
            $reply=new ReplyModel();
            $id=$reply->addReply($this->request->post());
            if(!empty($id)){
                return \zbcjson();
            }
            return \zbccjson(false,"添加失败");
        }
        
        return view();
    }

    public function update()
    {
        $reply=new ReplyModel();
        if($this->request->isAjax())
        {
            $id=$reply->addReply($this->request->post());
            if(!empty($id)){
                return \zbcjson();
            }
            return \zbcjson(false,"编译失败");
        }
        $get=$this->request->get();

        if(!array_key_exists("id",$get))
        {
            return $this->display("数据不存在");
        }

        $result=$reply->getReply("keyword",$get["id"]);
        $this->assign("model",$result);
        return view();
    }

    public function delete()
    {
        $post=$this->request->post();
        if(!array_key_exists("data",$post))
        {
            return \zbcjson(false,"数据不存在");
        }
       
        $id=ReplyModel::destroy($post["data"]);
        if(!empty($id)){
            return \zbcjson();
        }
        return \zbcjson(false,"删除失败");
    }
}